package com.lg.algorithm.base;

/**
 * 找到数字中 第一个个数
 * 这个数的左边都比他小，右边都比他大
 */
public class FindMidNum {
    public static void main(String[] args) {
        int[] arr = {3,2,1,5,6,3,0,8,9};
//        int[] arr = {1,2,3,4,5,6};
//        int[] arr = {4,3,2,1};
//        int[] arr = {1,3,2,4,8,9};
        int max = arr[0];
        int current = arr[0];
        boolean change = false;

        for (int i = 1; i < arr.length; i++) {
            if (current > arr[i]) {
                if (!change) {
                    change = true;
                    current = max;
                }
            } else {
                if (!change) {
                    max = arr[i];
                } else {
                    max = arr[i];
                    current = max;
                    change = false;
                }
            }
        }

        if (!change) {
            System.out.println(current);
        } else {
            System.out.println("无");
        }

    }
}
